﻿namespace Yom.WebService.Default
{
    using System.Collections.Generic;
    using Yom.Common;
    using Yom.Template;

    public class DefaultNotice : BasePage
    {
        public string OutWrite()
        {
            SetCommon();
            string ID = Factory.Request("ID");
            string P = Factory.Request("P");
            int page = (string.IsNullOrEmpty(P) ? 1 : P.ToInt());

            if (string.IsNullOrEmpty(ID))
            {
                SkinTheme.SetLabel("PageTitle", SiteLoad.Scheme.SiteTitle + " -- 网站公告");
                List<Yom.Model.Note> list = new Yom.Data.Note().GetList(15, page, "", "[IsTop]", false);
                SkinTheme.SetBlock("NoticeList", list.Count);
                int num = 0;
                foreach (Yom.Model.Note model in list)
                {
                    SkinTheme.SetElect(string.Format("NoticeList.HasUrl_{0}", num), !(string.IsNullOrEmpty(model.Url)));
                    SkinTheme.SetLabel(string.Format("NoticeList.Url_{0}", num), model.Url);
                    SkinTheme.SetLabel(string.Format("NoticeList.NoticeTitle_{0}", num), model.Title);
                    SkinTheme.SetLabel(string.Format("NoticeList.PostTime_{0}", num), model.PostTime.ToString());
                    SkinTheme.SetLabel(string.Format("NoticeList.ID_{0}", num), model.NoteID.ToString());
                    num++;
                }
                string Multi = Factory.GetPager(20, page, new Yom.Data.Note().GetCount(), "Index_<{page}>.ashx");
                SkinTheme.SetLabel("MultiPage", Multi.Replace("Index_1.ashx", "Index.ashx"));
                return SkinTheme.RunParse("NoticeList.html");
            }
            else
            {
                Yom.Model.Note notice = new Yom.Data.Note().GetModel(ID.ToInt());
                SkinTheme.SetLabel("PageTitle", notice.Title);
                SkinTheme.SetLabel("NoticeName", notice.Title);
                SkinTheme.SetLabel("NoticeContent", notice.Content.HtmlDeCode());
                return SkinTheme.RunParse("NoticeInfo.html");
            }
        }
    }
}